﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsServiceDemo
{
    using System.IO;

    using WindowsServiceApp;

    using Abp;
    using Abp.Castle.Logging.Log4Net;
    using Abp.IO;

    using Castle.Facilities.Logging;

    using Topshelf;

    class Program
    {
        private static AbpBootstrapper _bootstrapper;

        static Program()
        {
            _bootstrapper = AbpBootstrapper.Create<WindowsServiceDemoConsoleModule>();

        }

        static void Main(string[] args)
        {
            InitAbp();
            
            HostFactory.Run(x =>                                 
                {
                    x.Service<IWriteLogScheduler>(s =>                        
                        {
                            s.ConstructUsing(name => _bootstrapper.IocManager.Resolve<IWriteLogScheduler>());
                            s.WhenStarted(async tc => await tc.Start());             
                            s.WhenStopped(async tc => await tc.Stop());               
                        });
                    x.RunAsLocalSystem();
                    x.StartAutomatically();

                    x.SetDescription("Rende服务测试");        
                    x.SetDisplayName("RendeTestService");                       
                    x.SetServiceName("RendeTestService");                       
                });
            
        }

        static void InitAbp()
        {
            _bootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
                f => f.UseAbpLog4Net().WithConfig("log4net.config"));

            _bootstrapper.Initialize();
        }
    }
}
